﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BasicFramework.Components;
using BasicFramework.Rendering.Buffer.DirectX9;
using BasicFramework.Rendering.Primitives.Vertizes;
using BasicFramework.Rendering.Primitives.Indexes;
using BasicFramework.Services;
using BasicFramework.Services.Graphics;
using SlimDX;
using System.Drawing;
using BasicFramework.Devices.DirectX9;
using SlimDX.Direct3D9;

namespace Demo_App.Components
{
    class Grid : Component
    {
        private IGraphicsService<DX9DeviceContext> graphicsService;

        private DX9DynamicVertexBuffer<ColorVertex> vBuffer;
        private DX9DynamicIndexBuffer<Index> iBuffer;

        public override void Initialize(bool createDependencies)
        {
            base.Initialize(createDependencies);

            this.graphicsService = ServiceProvider.GetService<IGraphicsService<DX9DeviceContext>>();
        }

        public override void Start()
        {
            base.Start();
        }


        public override void Draw(float frame)
        {
            base.Draw(frame);
            vBuffer.SetBuffer(0);
            this.graphicsService.DeviceContext.Device.DrawPrimitives(PrimitiveType.LineList, 0, 3);
        }

        public override void Update(float frame)
        {
            base.Update(frame);
        }


        public override void LoadResources(bool loadAllContent)
        {
            base.LoadResources(loadAllContent);

            vBuffer = new DX9DynamicVertexBuffer<ColorVertex>(this.graphicsService.DeviceContext);

            vBuffer.Add(new ColorVertex(new Vector3(0.0f, 0.0f, 0), Color.White.ToArgb()));
            vBuffer.Add(new ColorVertex(new Vector3(15.0f, 0.0f, 0), Color.White.ToArgb()));

            vBuffer.Add(new ColorVertex(new Vector3(0.0f, 0.0f, 0), Color.White.ToArgb()));
            vBuffer.Add(new ColorVertex(new Vector3(0.0f, 32.0f, 0), Color.White.ToArgb()));

            vBuffer.Add(new ColorVertex(new Vector3(15.0f, 0.0f, 0), Color.White.ToArgb())); ;
            vBuffer.Add(new ColorVertex(new Vector3(15.0f, 32.0f, 0), Color.White.ToArgb()));

            vBuffer.Commit();



            iBuffer = new DX9DynamicIndexBuffer<Index>(this.graphicsService.DeviceContext);



        }

        public override void UnloadResources(bool unloadAllContent)
        {
            base.UnloadResources(unloadAllContent);

            this.iBuffer.Dispose();
            this.vBuffer.Dispose();
        }


    }
}
